package pkg.customer;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import retail.bo.CustomerBo;
import HibernateBeans.Invoice;
import HibernateBeans.ProductDetails;
public class CustomerAction extends Action {
	//Add
	private CustomerBo customerBo;

	public CustomerBo getCustomerBo() {
		return customerBo;
	}
	public void setCustomerBo(CustomerBo customerBo){
		this.customerBo=customerBo;
	}
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {

		String username=request.getUserPrincipal().getName();
		List<ProductDetails> lp=customerBo.getProducts(username);
		Invoice inv=customerBo.getCurrentInvoice(username);
		HttpSession session=request.getSession();
		session.setAttribute("username", username);
		session.setAttribute("products", lp);
		session.setAttribute("invoice", inv);
		return mapping.findForward("home");		
	}
	
}
